<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>攻略列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>
<div id="aaa"></div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">攻略列表</div>
                <div class="layui-card-body">
                    <div class="layui-form-item layui-form">
                        <!--<div class="layui-inline layui-form">-->
                            <!--<div class="layui-btn-group test-table-operate-btn">-->
                                <!--<button class="layui-btn" data-type="addadmin">发表攻略</button>-->
                            <!--</div>-->

                        <!--</div>-->
                         <div class="layui-inline">
                            <label class="layui-form-label">发布人</label>
                            <div class="layui-input-block">
                                <input type="text" name="nickname" id="nickname" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">标题</label>
                            <div class="layui-input-block">
                                <input type="text" name="title" id="title" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                       <div class="layui-inline">
                            <label class="layui-form-label">审核状态</label>
                            <div class="layui-input-block">
                                <select name="is_pass" lay-verify="" lay-search id="is_pass">
                                    <option value="">请选择</option> 
                                    <option value="1">通过</option> 
                                    <option value="2">拒绝</option> 
                                    <option value="0">未审核</option> 
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate">
                        <script type="text/html" id="is_use_switch">
                            <input type="checkbox" name="is_login" lay-skin="switch" lay-text="精选|非精选" lay-filter="is_use_switch" value="{{ d.is_select }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.is_select == 1 ? 'checked' : '' }}>
                        </script>
                        <script type="text/html" id="is_display">
                            <input type="checkbox" name="is_display" lay-skin="switch" lay-text="不显示|显示" lay-filter="is_display" value="{{ d.is_display }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.is_display == 1 ? 'checked' : '' }}>
                        </script>
                    </table>
                    <script type="text/html" id="test-table-operate-barDemo">
                        <a class="layui-btn layui-btn-xs" lay-event="showPic">查看</a>
                        <a class="layui-btn layui-btn-normal layui-btn-xs" id="showImg" lay-event="showImg">图片</a>
                        {{# if(d.is_pass==0){ }}
                        <a class="layui-btn layui-bg-green layui-btn-xs" lay-event="yesPass">审核</a>
                        {{# }else if(d.is_pass==1){ }}
                        <a class=" layui-btn layui-btn-disabled layui-btn-xs">通过</a>
                        <a class="layui-btn layui-bg-green layui-btn-xs" lay-event="del">删除</a>
                        <a class="layui-btn layui-bg-normal layui-btn-xs" lay-event="update">修改</a>
                        <a class="layui-btn  layui-bg-cyan layui-btn-xs" lay-event="like">刷点赞</a>
                        <a class="layui-btn  layui-bg-cyan layui-btn-xs" lay-event="comment">刷评论</a>
                        {{# } else if(d.is_pass==2){ }}
                        <a class="layui-btn layui-btn-disabled layui-btn-xs">不通过</a>
                        {{# } }}

                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="contentShow" style="display:none;padding: 30px;">
    <div id="consultation"></div>
</div>
<div id="editpassmodal"  style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group">
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">基础点赞数</label>-->
            <!--<div class="layui-input-block">-->
                <!--<input type="text" name="set_like_num"  id="set_like_num" class="layui-input">-->
                <!--<input type="hidden" name="id"  id="mid">-->
                <!--<input type="hidden" name="uid"  id="uid">-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">基础分享数</label>
            <div class="layui-input-block">
                <input type="text" name="set_share_num"  id="set_share_num" class="layui-input">
            </div>
        </div>
        <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">基础收藏数</label>-->
        <!--<div class="layui-input-block">-->
        <!--<input type="text" name="set_collect_num"  id="set_collect_num" class="layui-input">-->
        <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-inline" style="left: 0;">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="editColumnsubmit">立即提交</button>
                </div>
            </div>
        </div>
    </form>
</div>


<div id="like"  style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group">

        <div class="layui-form-item" style="margin-top: 20px">
            <label class="layui-form-label">点赞数</label>
            <div class="layui-input-block">
                <input type="text" name="set_like_num"  id="like_num" class="layui-input" lay-verify="required" placeholder="请输入点赞个数">
                <input type="hidden" name="id"  id="m_id">
                <input type="hidden" name="uid"  id="u_id">
            </div>
        </div>
        <div class="layui-form-item">
        <label class="layui-form-label">开始时间</label>
            <div class="layui-input-block">
                <input type="text" name="time"  id="time" class="layui-input" lay-verify="required" placeholder="开始点赞时间">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-block">
                <input type="text" name="end_time" id="end_time" class="layui-input" lay-verify="required" placeholder="结束点赞时间">
            </div>
        </div>
        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-inline" style="left: 0;">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="editLike">立即提交</button>
                </div>
            </div>
        </div>
    </form>
</div>


<div id="comment"  style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group">

        <div class="layui-form-item" style="margin-top: 20px">
            <label class="layui-form-label">评论数</label>
            <div class="layui-input-block">
                <input type="text" name="set_comment_num"  id="set_comment_num" class="layui-input" lay-verify="required" placeholder="请输入评论条数">
                <input type="hidden" name="id"  id="mid">
                <input type="hidden" name="uid"  id="uid">
            </div>
        </div>
        <div class="layui-form-item">
        <label class="layui-form-label">开始时间</label>
            <div class="layui-input-block">
                <input type="text" name="starttime"  id="starttime" class="layui-input" lay-verify="required" placeholder="开始点赞时间">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-block">
                <input type="text" name="endtime" id="endtime" class="layui-input" lay-verify="required" placeholder="结束点赞时间">
            </div>
        </div>
        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-inline" style="left: 0;">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="addComment">立即提交</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('Method/methodlist')}"
            ,height: 'full-100'
            ,cols: [[
                {field:'mid',width:50,align:'center', title: 'ID'}
                ,{field:'title',align:'center',title: '攻略标题'}
                ,{field:'view_name',align:'center',title: '攻略景点'}
                ,{field:'nickname',align:'center',title: '发布人'}
                ,{field:'update_time', align:'center', title: '通过时间'}
                ,{field:'like_num',align:"center",title: '点赞数'}
                ,{field:'comment_num',align:"center",title: '评论数'}
                ,{field:'share_num',align:"center",title: '转发数'}
                ,{field:'is_select', align:'center', title: '精选攻略',templet: '#is_use_switch'}
                ,{field:'is_display', align:'center', title: '是否显示',templet: '#is_display'}
                ,{align:'center',width:400, title: '操作', toolbar: '#test-table-operate-barDemo'}
            ]]
            ,page:true
            ,limit:20
        });

        form.render(null,'component-form-group');

        laydate.render({
            elem: '#search_time'
        });

        //时间选择器
        laydate.render({
            elem: '#time'
            ,type: 'datetime'
        });

        laydate.render({
            elem: '#end_time'
            ,type: 'datetime'
        });
         laydate.render({
            elem: '#end_time'
            ,type: 'datetime'
        });
          laydate.render({
            elem: '#endtime'
            ,type: 'datetime'
        });
           laydate.render({
            elem: '#starttime'
            ,type: 'datetime'
        });
        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;
            if(obj.event === 'showPic'){
                var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                $.ajax({
                    url: "{:url('Method/getContent')}",
                    type: 'post',
                    dataType: 'json',
                    data: {id:data.mid},
                    success: function(msg){
                        layer.close(loading);
                        if (msg.code === 0) {
                            // $.each(msg.data ,function (i,item) {
                            //     $("#consultation").append("<p>"+item.data+"</p>");
                            //     $("#consultation").append('<div style="width: 100%"><img style="width: 100%" src="'+item.image+'"> </div>');
                            // })
                            //
                            //
                            // var addmodal = layer.open({
                            //     title: '投稿内容'
                            //     , type: 1
                            //     , shadeClose: true
                            //     , area:['800px','800px']
                            //     , content: $('#contentShow')
                            // });
                            window.open("/index/circle/methodPreshow/id/"+data.mid+".html")
                        }else{
                            layer.msg('移动失败',{icon:2,time:1000});
                        }
                    }
                });
            } else if(obj.event === 'showImg'){
                if (!data.image){
                    layer.msg('暂无图片',{time:1000});
                    return false;
                }
                var img_src = data.image;
                var img_src_arr = img_src.split(',');

                var img_src_data = {};
                img_src_data.title = '投稿图片';
                img_src_data.id = data.id;
                img_src_data.start = 0;
                img_src_data.data =[];

                var src = {};

                for(var i=0;i<img_src_arr.length;i++){
                    src = {};
                    var num = i+1;
                    src.alt = '投稿图片'+ num;
                    src.pid = i;
                    src.src = img_src_arr[i];
                    src.thumb = img_src_arr[i];
                    console.log(src);
                    img_src_data.data.push(src);
                }
                layer.photos({
                    photos: img_src_data
                    ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }else if(obj.event === 'del'){
                layer.confirm('确认删除"' + data.title + '"吗？', function(index){
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: "{:url('Method/delMethod')}",
                        type: 'post',
                        dataType: 'json',
                        data: {id:data.mid},
                        success: function(msg){
                            layer.close(loading);
                            if (msg.code == 0) {
                                obj.del();
                                layer.close(index);
                            }else{
                                layer.msg(msg.message,{icon:2,time:1000});
                            }
                        }
                    });
                });
            }else if(obj.event === 'update'){
               // window.location.href="{:url('Method/editMethod')}?id="+data.mid;
                $('#mid').val(data.mid);
                $('#uid').val(data.uid);
                $('#set_like_num').val(data.set_like_num);
                $('#set_share_num').val(data.set_share_num);
                $('#set_collect_num').val(data.set_collect_num);
                var editpassmodal = layer.open({
                    title:'修改基础参数'
                    ,type: 1
                    ,shadeClose: true
                    ,area: admin.screen() < 2 ? ['60%'] : ['500px']
                    ,content: $('#editpassmodal')
                });
            }else if(obj.event === 'yesPass'){
                layer.confirm('攻略投稿申请',{
                    btn: ['通过', '不通过', '取消']
                    ,yes:function(){
                        var loading = layer.load(1, {
                            shade: [0.1,'#fff'] //0.1透明度的白色背景
                        });
                        $.ajax({
                            url: "{:url('Method/methodIsPass')}",
                            type: 'post',
                            dataType: 'json',
                            data: {id:data.mid,uid:data.uid,title:data.title,is_pass:1},
                            success: function(msg){
                                layer.close(loading);
                                if (msg === 0) {
                                    layer.msg('已通过', {icon: 1, time: 1000},function(){
                                        window.location.reload();
                                    });
                                }else{
                                    layer.msg('系统错误',{icon:2,time:1000});
                                }
                            }
                        });
                    }
                    ,btn2:function(){
                        var loading = layer.load(1, {
                            shade: [0.1,'#fff'] //0.1透明度的白色背景
                        });
                        $.ajax({
                            url: "{:url('Method/methodIsPass')}",
                            type: 'post',
                            dataType: 'json',
                            data: {id: data.mid,uid:data.uid,title:data.title,is_pass:2},
                            success: function (msg) {
                                layer.close(loading);
                                if (msg === 0) {
                                    layer.msg('未通过', {icon: 1, time: 1000},function(){
                                        window.location.reload();
                                    });
                                } else {
                                    layer.close(loading);
                                    layer.msg('系统错误', {icon: 2, time: 1000});
                                }
                            }
                        })
                    }
                    ,btn3:function(){
                        layer.closeAll();
                    }
                });
            }else if(obj.event === 'like'){
                $('#m_id').val(data.mid);
                $('#u_id').val(data.uid);
                var editpassmodal = layer.open({
                    title:'添加假点赞'
                    ,type: 1
                    ,shadeClose: true
                    ,area: admin.screen() < 2 ? ['60%'] : ['500px']
                    ,content: $('#like')
                });
            }else if(obj.event === 'comment'){
                $('#mid').val(data.mid);
                $('#uid').val(data.uid);
                var editpassmodal = layer.open({
                    title:'添加假评论'
                    ,type: 1
                    ,shadeClose: true
                    ,area: admin.screen() < 2 ? ['60%'] : ['500px']
                    ,content: $('#comment')
                });
            }

        });
        //开关修改管理员状态
        form.on('switch(is_use_switch)', function(obj){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);

            var is_select = this.checked ? '1' : '0';

            $.ajax({
                url: "{:url('Method/isSelect')}",
                type: 'post',
                dataType: 'json',
                data: {id:json.mid,is_select:is_select},
                success: function(info){
                    if (info.code === 1) {
                        layer.closeAll()

                    }else{
                        layer.msg(info,{icon:2,time:1000},function(){
                            //layer.close(loading);
                            window.location.reload();
                        });
                    }
                }
            })
        });
        //开关修改管理员状态
        form.on('switch(is_display)', function(obj){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);

            var is_display = this.checked ? '1' : '0';

            $.ajax({
                url: "{:url('Method/isShow')}",
                type: 'post',
                dataType: 'json',
                data: {id:json.mid,is_display:is_display},
                success: function(info){
                    if (info.code === 1) {
                        layer.closeAll()

                    }else{
                        layer.msg(info,{icon:2,time:1000},function(){
                            //layer.close(loading);
                            window.location.reload();
                        });
                    }
                }
            })
        });
        form.on('submit(editColumnsubmit)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: "{:url('Method/updateMethod')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function(info){
                    if (info.code === 0) {
                        layer.msg('修改成功',{icon:1,time:2000},function(){
                            layer.closeAll();
                            window.location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg('修改失败',{icon:2,time:1000})
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


        form.on('submit(editLike)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: "{:url('Method/editLike')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function(info){
                    if (info.code === 0) {
                        layer.msg('修改成功',{icon:1,time:2000},function(){
                            layer.closeAll();
                            window.location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg('修改失败',{icon:2,time:1000})
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        form.on('submit(addComment)', function(data){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: "{:url('Method/addMethodFalseApp')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function(info){
                    if (info.code === 0) {
                        layer.msg('修改成功',{icon:1,time:2000},function(){
                            layer.closeAll();
                            window.location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg('修改失败',{icon:2,time:1000})
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        var $ = layui.$, active = {
            addadmin: function() {
                window.location.href="{:url('Method/addMethod')}";
            },
            searchUserButton:function(){
                var title  = $('#title').val();
                var is_pass = $('#is_pass').val();
                var nickname = $('#nickname').val();
                table.reload('test-table-operate', {
                    where: {
                        title:title,
                        is_pass:is_pass,
                        nickname:nickname

                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            }
        };
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>


</body>
</html>